﻿using System;
using System.Windows.Forms;

namespace Rsdn.Janus
{
    /// <summary>
    /// Окно ввода ID топика.
    /// </summary>
	internal partial class EnterTopicMessageIdForm : Form
    {
private int messageId = -1;

        internal EnterTopicMessageIdForm()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Gets or sets the message id.
        /// </summary>
        /// <value>The message id.</value>
        public int MessageId
        {
            get
            {
                return messageId;
            }

            set
            {
                messageId = value;
            }
        }

        private void _idBox_TextChanged(object sender, EventArgs e)
        {
            bool isValid = true;

            try
            {
                //string input = ((TextBox)sender).Text;
                string input = _idBox.Text;

                if (!string.IsNullOrEmpty(input))
                {
                    JanusProtocolInfo janusProtocolInfo = JanusProtocolInfo.Parse(input);
                    if (janusProtocolInfo != null && janusProtocolInfo.IsId)
                    {
                        MessageId = janusProtocolInfo.Id;
                    }
                    else
                    {
                        MessageId = int.Parse(input);
                    }
                }
                else
                {
                    isValid = false;
                }
            }
            catch
            {
                isValid = false;
            }

            //_labelMessageIdIsText.Text = string.Format(SR.EnterTopicMessageIdForm.MessageIdIsTextFormat, MessageId);

            //_labelMessageIdIsText.Visible = isDigit;
            _okButton.Enabled = isValid;
        }
        }
}